package it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners;

import com.google.gwt.user.client.Element;

public class FClickListener {

    public FClickListener(Element e, FClickListenerHandler handler) {
        attachClickHandler(e, handler);
    }

    public static void setClickEvent(Element e, FClickListenerHandler handler) {
        new FClickListener(e, handler);
    }

    private static native void dispatchClickEvent(FClickListenerHandler handler) /*-{
            handler.@it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FClickListenerHandler::onClick()();
        }-*/;

    private native void attachClickHandler(Element e, FClickListenerHandler hendler) /*-{

         e.onclick = hendler;

               if ($wnd.addEventListener && !$wnd.opera) {
                   e.addEventListener('onClick', @it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FClickListener::dispatchClickEvent(Lit/fuzzylogics/fuzzywidgetsLibrary/client/FuzzyListeners/FClickListenerHandler;), false);
               }

          e.onclick =  function() {
                  @it.fuzzylogics.fuzzywidgetsLibrary.client.FuzzyListeners.FClickListener::dispatchClickEvent(Lit/fuzzylogics/fuzzywidgetsLibrary/client/FuzzyListeners/FClickListenerHandler;)(hendler);
          }

      }-*/;

}